package 多线程.创建多线程.实现Runnable;



public class myRunnable implements Runnable {
    private int num =50;
    @Override
     public void run() {
        test();

    }
    synchronized public void test(){
        while(num>0){
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread().getName()+"抢到了第"+num--+"张票");
        }
    }

    public static void main(String[] args) {
        myRunnable myRunnable = new myRunnable();
        Thread t1 = new Thread(myRunnable,"路人甲");
        Thread t2 = new Thread(myRunnable,"路人乙");
        Thread t3 = new Thread(myRunnable,"路人丙");
        t1.start();
        t2.start();
        t3.start();


    }
}
